<?php
include("../../includes/dbInfo.php");
function listSwimmers($eventID) {
	echo "<div class='featured-post'>
            <div class='post-title'>
                <h2>Add Comments</h2>
			</div><div id='commentBox' class='white_content'><a id='closeBox' class='closeBoxLink' href='#' onclick = 'closeBox();'>Close</a>
			<div id='commentText'></div></div>";
			
	$query = "SELECT `accounts`.`name` AS name, `ls_events`.`name` AS eName, 
				`ls_events`.`eventType` AS type, `ls_events`.`eventLength` AS length,
				`swimPerformance`.`swimmerID` AS swimmerID,
				`swimPerformance`.`time` AS time, 
				`swimPerformance`.`place` AS place
				FROM `accounts`, `swimPerformance`, `ls_events`
				WHERE `swimPerformance`.`eventID` = '$eventID' 
				AND `swimPerformance`.`swimmerID` = `accounts`.`userID`
				AND `ls_events`.`eventID` = `swimPerformance`.`eventID`
				ORDER BY time ASC";
	
	$result = mysql_query($query) or die("Error getting list of swimmers: " . mysql_error());
	// Show a message if no swimmers were in this event.
	if(mysql_num_rows($result) == 0) {
		echo "No swimmers participated in this event.";
	}
	else {
		echo "<div class='post-entry'><table id='blueTable'><tr><th>Name</th><th>Time</th><th>Place</th><th>Add/Edited Comment</th></tr>";
		$rows = mysql_fetch_assoc($result);
		echo "<br/><h3>" . $rows["eName"] . " " . $rows["type"]. " " . $rows["length"] . "</h3>";
		mysql_data_seek($result, 0);
		$i = 0;
		while($rows = mysql_fetch_assoc($result)) {
			// Use the $style variable to alternate the css class.
			$style = (($i % 2) == 0)? 'even' : 'odd';
			echo "<tr class='$style'><td>" . $rows['name'] . "</td><td>" . $rows['time'] . "</td><td>" . $rows['place'] . 
				"</td><td><a href='javascript:addComment(" . $eventID . ", " . $rows['swimmerID'] . ");'>Add/Edit</a></td></tr>";
			$i++;
		}
		echo "</table></div>";
	}
	echo "</div><div id='blackOverlay' class='blackOverlay'></div>";
}
?>